﻿
#region Usings

using FasterWPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

#endregion

namespace FasterWPFDemo
{
    public static class TabControlService
    {
        public static void InitTabControl(TabControl tabCtl)
        {
            tabCtl.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, 24, 1);
        }

        public static void SelectTab(TabControl tabCtl, int index)
        {
            tabCtl.SelectedIndex = (index-1);
        }

        private static void RemoveTabItem(object o, TabItem tabItm1, string tabControlGuid)
        {
            Application.Current.Properties["TabToBeRemoved"] = "Custom" + tabItm1.Name;
            (o as TabControl).RemoveByKey(tabControlGuid);

            //REMOVE ANY HARDCODED GLOBAL REFERENCES
            GlobalStoreService.ClearGlobalStoreByGuid(tabControlGuid);
        }

        public static class UserControlRegionGuids
        {
            public static string One = "1c9276d4-42fe-4702-b081-9964de774326";
            public static string Two = "c155b1ce-f674-44d2-b226-fc8b5ca45bdf";
            public static string Three = "d69851b7-2da6-4ff2-b637-f3f0c94c3ebe";
            public static string Four = "5e7690fc-1bef-4cde-aa99-fee7d1defc82";
            public static string Five = "28434a60-e219-4d17-a734-c3c890658d60";
            public static string Six = "6c401c2b-0dc3-470a-8c8f-31325b0fef58";
            public static string Seven =  "ed050f6b-15d5-4118-84a1-49202982710d";
            public static string Eight = "b0ec4438-ade2-48a2-adc1-8e77c0f411b2";
            public static string Nine = "9fb45473-f377-45d8-bd41-e97f1b1353a5";
            public static string Ten = "5515cb0d-5f37-46df-9a59-c4ee4403c8f5";
        }

        public static TabItem CreateTabItem1(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid0, TabControl tabCtl, string userCtlGuid1)
        {
            //Create Tab Item
            TabItem tabItm1 = new TabItem() { Name = "TabItem1" };
            tabItm1.Initialize(double.NaN, double.NaN, ContainerType.Grid);
            tabItm1.SetCompositeGridDimensions<TabItem>(double.NaN, double.NaN, 1, 1, double.NaN, GridUnitType.Pixel, double.NaN, GridUnitType.Pixel);
            tabItm1.Background = Brushes.Purple;
            tabItm1.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            //Create Custom User Control (Custom Tab Item)
            TabItem01 tabItem1UserControl = new TabItem01(); //CustomTabItem
            tabItem1UserControl.UserControlGuid = userCtlGuid1;
            tabItem1UserControl.LoadUserControl();

            //Add Custom User Control to Region
            UserControlRegion tabItem1Region = new UserControlRegion(backgroundColor);
            string tabItem1Regionkey = UserControlRegionGuids.One; //constant
            tabItem1Region.AddUserControl(tabItem1UserControl, tabItem1Regionkey);

            //Add Region to Tab Item
            tabItm1.BeginComposite<TabItem>(tabguid0)
                   .AddExisting<Border, TabItem>(0, 0, tabItem1Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            //Add Tab Item to Tab Control
            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.One)
                .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                {
                    //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                    RemoveTabItem(o, tabItm1, GlobalStoreService.TabControlGuids.One);

                }), tabItm1)
                .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store to be Fired From Anywhere
            TabItemActions.AddUserControl<TabItem01>(GlobalStoreService.TabControlGuids.One, userCtlGuid1, "TabItem1AddUserControl", tabItem1UserControl, tabItem1Region, tabItem1Regionkey);
            TabItemActions.RemoveUserControl<TabItem01>(GlobalStoreService.TabControlGuids.One, userCtlGuid1, "TabItem1RemoveUserControl", tabItem1UserControl, tabItem1Region, tabItem1Regionkey);
            
            return tabItm1;
        }

        public static TabItem CreateTabItem2(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid1, TabControl tabCtl, string userCtlGuid2)
        {
            TabItem tabItm2 = new TabItem() { Name = "TabItem2" };
            tabItm2.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);
            tabItm2.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem02 tabItem2UserControl = new TabItem02(); //CustomTabItem
            tabItem2UserControl.UserControlGuid = userCtlGuid2;
            tabItem2UserControl.LoadUserControl();

            UserControlRegion tabItem2Region = new UserControlRegion(backgroundColor);

            string tabItem2Regionkey = UserControlRegionGuids.Two; //constant
            tabItem2Region.AddUserControl(tabItem2UserControl, tabItem2Regionkey);

            tabItm2.BeginComposite<TabItem>(tabguid1)
                   .AddExisting<Border, TabItem>(0, 0, tabItem2Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Two)
                   .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                   {
                       //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                       RemoveTabItem(o, tabItm2, GlobalStoreService.TabControlGuids.Two);

                   }), tabItm2)
                   .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem02>(GlobalStoreService.TabControlGuids.Two, userCtlGuid2, "TabItem2AddUserControl", tabItem2UserControl, tabItem2Region, tabItem2Regionkey);
            TabItemActions.RemoveUserControl<TabItem02>(GlobalStoreService.TabControlGuids.Two, userCtlGuid2, "TabItem2RemoveUserControl", tabItem2UserControl, tabItem2Region, tabItem2Regionkey);
           
            return tabItm2;
        }

        public static TabItem CreateTabItem3(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid2, TabControl tabCtl, string userCtlGuid3)
        {
            TabItem tabItm3 = new TabItem(){ Name = "TabItem3" };
            tabItm3.Initialize(double.NaN, double.NaN, ContainerType.DockPanel);
            tabItm3.SetCompositeDockPanelLastChildFill<TabItem>(true);

            tabItm3.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem03 tabItem3UserControl = new TabItem03(); //CustomTabItem
            tabItem3UserControl.UserControlGuid = userCtlGuid3;
            tabItem3UserControl.LoadUserControl();

            UserControlRegion tabItem3Region = new UserControlRegion(backgroundColor);

            string tabItem3Regionkey = UserControlRegionGuids.Three; //constant
            tabItem3Region.AddUserControl(tabItem3UserControl, tabItem3Regionkey);

            tabItm3.BeginComposite<TabItem>(tabguid2)
                   .AddExisting<Border, TabItem>(0, 0, tabItem3Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Three)
                   .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                   {
                       //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                       RemoveTabItem(o, tabItm3, GlobalStoreService.TabControlGuids.Three);
                   
                   }), tabItm3)
                   .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem03>(GlobalStoreService.TabControlGuids.Three, userCtlGuid3, "TabItem3AddUserControl", tabItem3UserControl, tabItem3Region, tabItem3Regionkey);
            TabItemActions.RemoveUserControl<TabItem03>(GlobalStoreService.TabControlGuids.Three, userCtlGuid3, "TabItem3RemoveUserControl", tabItem3UserControl, tabItem3Region, tabItem3Regionkey);
           
            return tabItm3;
        }

        public static TabItem CreateTabItem4(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid3, TabControl tabCtl, string userCtlGuid4)
        {
            TabItem tabItm4 = new TabItem() { Name = "TabItem4" };
            tabItm4.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm4.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem04 tabItem4UserControl = new TabItem04(); //CustomTabItem
            tabItem4UserControl.UserControlGuid = userCtlGuid4;
            tabItem4UserControl.LoadUserControl();

            UserControlRegion tabItem4Region = new UserControlRegion(backgroundColor);

            string tabItem4Regionkey = UserControlRegionGuids.Four; //constant
            tabItem4Region.AddUserControl(tabItem4UserControl, tabItem4Regionkey);

            tabItm4.BeginComposite<TabItem>(tabguid3)
                   .AddExisting<Border, TabItem>(0, 0, tabItem4Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Four)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm4, GlobalStoreService.TabControlGuids.Four);

                  }), tabItm4)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem04>(GlobalStoreService.TabControlGuids.Four, userCtlGuid4, "TabItem4AddUserControl", tabItem4UserControl, tabItem4Region, tabItem4Regionkey);
            TabItemActions.RemoveUserControl<TabItem04>(GlobalStoreService.TabControlGuids.Four, userCtlGuid4, "TabItem4RemoveUserControl", tabItem4UserControl, tabItem4Region, tabItem4Regionkey);
           
            return tabItm4;
        }

        public static TabItem CreateTabItem5(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid4, TabControl tabCtl, string userCtlGuid5)
        {
            TabItem tabItm5 = new TabItem() { Name = "TabItem5" };
            tabItm5.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm5.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem05 tabItem5UserControl = new TabItem05();  //CustomTabItem
            tabItem5UserControl.UserControlGuid = userCtlGuid5;
            tabItem5UserControl.LoadUserControl();

            UserControlRegion tabItem5Region = new UserControlRegion(backgroundColor);

            string tabItem5Regionkey = UserControlRegionGuids.Five; //constant
            tabItem5Region.AddUserControl(tabItem5UserControl, tabItem5Regionkey);

            tabItm5.BeginComposite<TabItem>(tabguid4)
                   .AddExisting<Border, TabItem>(0, 0, tabItem5Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Five)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //Dispose WinFormHost control (which is used to display Charts)

                      tabItem5UserControl.DisposeWinFormHost();

                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm5, GlobalStoreService.TabControlGuids.Five);

                  }), tabItm5)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem05>(GlobalStoreService.TabControlGuids.Five, userCtlGuid5, "TabItem5AddUserControl", tabItem5UserControl, tabItem5Region, tabItem5Regionkey);
            TabItemActions.RemoveUserControl<TabItem05>(GlobalStoreService.TabControlGuids.Five, userCtlGuid5, "TabItem5RemoveUserControl", tabItem5UserControl, tabItem5Region, tabItem5Regionkey);
            
            return tabItm5;
        }

        public static TabItem CreateTabItem6(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid5, TabControl tabCtl, string userCtlGuid6)
        {
            TabItem tabItm6 = new TabItem() { Name = "TabItem6" };
            tabItm6.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm6.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem06 tabItem6UserControl = new TabItem06();  //CustomTabItem
            tabItem6UserControl.UserControlGuid = userCtlGuid6;
            tabItem6UserControl.LoadUserControl();

            UserControlRegion tabItem6Region = new UserControlRegion(backgroundColor);

            string tabItem6Regionkey = UserControlRegionGuids.Six; //constant
            tabItem6Region.AddUserControl(tabItem6UserControl, tabItem6Regionkey);

            tabItm6.BeginComposite<TabItem>(tabguid5)
                   .AddExisting<Border, TabItem>(0, 0, tabItem6Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Six)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm6, GlobalStoreService.TabControlGuids.Six);

                  }), tabItm6)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem06>(GlobalStoreService.TabControlGuids.Six, userCtlGuid6, "TabItem6AddUserControl", tabItem6UserControl, tabItem6Region, tabItem6Regionkey);
            TabItemActions.RemoveUserControl<TabItem06>(GlobalStoreService.TabControlGuids.Six, userCtlGuid6, "TabItem6RemoveUserControl", tabItem6UserControl, tabItem6Region, tabItem6Regionkey);
            
            return tabItm6;
        }

        public static TabItem CreateTabItem7(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid6, TabControl tabCtl, string userCtlGuid7)
        {
            TabItem tabItm7 = new TabItem() { Name = "TabItem7" };
            tabItm7.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm7.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem07 tabItem7UserControl = new TabItem07();  //CustomTabItem
            tabItem7UserControl.UserControlGuid = userCtlGuid7;
            tabItem7UserControl.LoadUserControl();

            UserControlRegion tabItem7Region = new UserControlRegion(backgroundColor);

            string tabItem7Regionkey = UserControlRegionGuids.Seven; //constant
            tabItem7Region.AddUserControl(tabItem7UserControl, tabItem7Regionkey);

            tabItm7.BeginComposite<TabItem>(tabguid6)
                   .AddExisting<Border, TabItem>(0, 0, tabItem7Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Seven)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm7, GlobalStoreService.TabControlGuids.Seven);

                  }), tabItm7)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem07>(GlobalStoreService.TabControlGuids.Seven, userCtlGuid7, "TabItem7AddUserControl", tabItem7UserControl, tabItem7Region, tabItem7Regionkey);
            TabItemActions.RemoveUserControl<TabItem07>(GlobalStoreService.TabControlGuids.Seven, userCtlGuid7, "TabItem7RemoveUserControl", tabItem7UserControl, tabItem7Region, tabItem7Regionkey);
            
            return tabItm7;
        }

        public static TabItem CreateTabItem8(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid7, TabControl tabCtl, string userCtlGuid8)
        {
            TabItem tabItm8 = new TabItem() { Name = "TabItem8" };
            tabItm8.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm8.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem08 tabItem8UserControl = new TabItem08();  //CustomTabItem
            tabItem8UserControl.UserControlGuid = userCtlGuid8;
            tabItem8UserControl.LoadUserControl();

            UserControlRegion tabItem8Region = new UserControlRegion(backgroundColor);

            string tabItem8Regionkey = UserControlRegionGuids.Eight; //constant
            tabItem8Region.AddUserControl(tabItem8UserControl, tabItem8Regionkey);

            //TabControl -> CustomTabItem -> TabItem (tabItm8) -> Border (user control region) -> UserControl (TabItem08)

            tabItm8.BeginComposite<TabItem>(tabguid7)
                   .AddExisting<Border, TabItem>(0, 0, tabItem8Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Eight)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) => 
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm8, GlobalStoreService.TabControlGuids.Eight);

                  }), tabItm8)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem08>(GlobalStoreService.TabControlGuids.Eight, userCtlGuid8, "TabItem8AddUserControl", tabItem8UserControl, tabItem8Region, tabItem8Regionkey);
            TabItemActions.RemoveUserControl<TabItem08>(GlobalStoreService.TabControlGuids.Eight, userCtlGuid8, "TabItem8RemoveUserControl", tabItem8UserControl, tabItem8Region, tabItem8Regionkey);
            
            return tabItm8;
        }

        public static TabItem CreateTabItem9(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid8, TabControl tabCtl, string userCtlGuid9)
        {
            TabItem tabItm9 = new TabItem() { Name = "TabItem9" };
            tabItm9.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm9.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem09 tabItem9UserControl = new TabItem09();  //CustomTabItem
            tabItem9UserControl.UserControlGuid = userCtlGuid9;
            tabItem9UserControl.LoadUserControl();

            UserControlRegion tabItem9Region = new UserControlRegion(backgroundColor);

            string tabItem9Regionkey = UserControlRegionGuids.Nine; //constant
            tabItem9Region.AddUserControl(tabItem9UserControl, tabItem9Regionkey);

            tabItm9.BeginComposite<TabItem>(tabguid8)
                   .AddExisting<Border, TabItem>(0, 0, tabItem9Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Nine)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm9, GlobalStoreService.TabControlGuids.Nine);

                  }), tabItm9)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem09>(GlobalStoreService.TabControlGuids.Nine, userCtlGuid9, "TabItem9AddUserControl", tabItem9UserControl, tabItem9Region, tabItem9Regionkey);
            TabItemActions.RemoveUserControl<TabItem09>(GlobalStoreService.TabControlGuids.Nine, userCtlGuid9, "TabItem9RemoveUserControl", tabItem9UserControl, tabItem9Region, tabItem9Regionkey);
           
            return tabItm9;
        }

        public static TabItem CreateTabItem10(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid9, TabControl tabCtl, string userCtlGuid10)
        {
            TabItem tabItm10 = new TabItem() { Name = "TabItem10" };
            tabItm10.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm10.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();

            TabItem10 tabItem10UserControl = new TabItem10();  //CustomTabItem
            tabItem10UserControl.UserControlGuid = userCtlGuid10;
            tabItem10UserControl.LoadUserControl();

            UserControlRegion tabItem10Region = new UserControlRegion(backgroundColor);

            string tabItem10Regionkey = UserControlRegionGuids.Ten; //constant
            tabItem10Region.AddUserControl(tabItem10UserControl, tabItem10Regionkey);

            tabItm10.BeginComposite<TabItem>(tabguid9)
                   .AddExisting<Border, TabItem>(0, 0, tabItem10Region)
                   .EndComposite<TabItem, TabItemArgs>(null);

            tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Ten)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm10, GlobalStoreService.TabControlGuids.Ten);

                  }), tabItm10)
                  .EndComposite<TabControl, TabControlArgs>(null);

            //Store Actions in Global Store on Application object
            TabItemActions.AddUserControl<TabItem10>(GlobalStoreService.TabControlGuids.Ten, userCtlGuid10, "TabItem10AddUserControl", tabItem10UserControl, tabItem10Region, tabItem10Regionkey);
            TabItemActions.RemoveUserControl<TabItem10>(GlobalStoreService.TabControlGuids.Ten, userCtlGuid10, "TabItem10RemoveUserControl", tabItem10UserControl, tabItem10Region, tabItem10Regionkey);
            
            return tabItm10;
        }

        /// <summary>
        ///  Create TabItem 10, Allowing Setting Custom Highlight and Border Colors
        /// </summary>
        /// <param name="tabName"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="tabLabelBackground"></param>
        /// <param name="foreground"></param>
        /// <param name="colorOfTheX"></param>
        /// <param name="tabItemUnderlineColor"></param>
        /// <param name="tabguid9"></param>
        /// <param name="tabCtl"></param>
        /// <param name="userCtlGuid10"></param>
        /// <param name="tabBorderBrush"></param>
        /// <param name="tabBackgroundColor"></param>
        /// <param name="tabMouseOverBorderBrush"></param>
        /// <param name="tabMouseOverColor"></param>
        /// <param name="tabItemSelectedBackground"></param>
        /// <param name="tabItemDisabledBackground"></param>
        /// <param name="tabItemDisabledBorderBrush"></param>
        /// <returns></returns>
        public static TabItem CreateTabItem10(string tabName, Brush backgroundColor, Brush tabLabelBackground, Brush foreground, Brush colorOfTheX, Brush tabItemUnderlineColor, string tabguid9, TabControl tabCtl, string userCtlGuid10, string tabBorderBrush, string tabBackgroundColor, string tabMouseOverBorderBrush, string tabMouseOverColor, string tabItemSelectedBackground, string tabItemDisabledBackground, string tabItemDisabledBorderBrush)
        {
            TabItem tabItm10 = new TabItem() { Name = "TabItem10" };
            tabItm10.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel);

            tabItm10.BeginSettings<TabItem>().SetItemBorderSettings<TabItem>(double.NaN, double.NaN, Brushes.Black, new Thickness(1)).EndSettings<TabItem>();
            TabItem10 tabItem10UserControl = new TabItem10();  //CustomTabItem
            tabItem10UserControl.UserControlGuid = userCtlGuid10;
            tabItem10UserControl.LoadUserControl();

            UserControlRegion tabItem10Region = new UserControlRegion(backgroundColor);

            string tabItem10Regionkey = UserControlRegionGuids.Ten; //constant
            tabItem10Region.AddUserControl(tabItem10UserControl, tabItem10Regionkey);

            tabItm10.BeginComposite<TabItem>(tabguid9)
                   .AddExisting<Border, TabItem>(0, 0, tabItem10Region)
                   .EndComposite<TabItem, TabItemArgs>(null);


            //Allowing Setting Custom Highlight and Border Colors
            tabItm10.Template = tabItm10.ApplyTabItemStrategy(tabBorderBrush, tabBackgroundColor, tabMouseOverBorderBrush, tabMouseOverColor, tabItemSelectedBackground, tabItemDisabledBackground, tabItemDisabledBorderBrush);


            Border b = tabCtl.BeginComposite<TabControl>(GlobalStoreService.TabControlGuids.Ten)
                  .AddCustomTabItem<TabControl>(0, 0, FasterWPF.Factory.NewTabHeader(tabCtl, foreground, tabLabelBackground, colorOfTheX, tabItemUnderlineColor, tabName, false, (o, e) =>
                  {
                      //This is the Close Tab Action - action that fires upon clicking the X on the Tab
                      RemoveTabItem(o, tabItm10, GlobalStoreService.TabControlGuids.Ten);

                  }), tabItm10)
                  .EndComposite<TabControl, TabControlArgs>(null);
                  
            //b.Name = "hey";  //testing selectors - identifying this Border by name  

            //Store Actions in Global Store on Application object
       TabItemActions.AddUserControl<TabItem10>(GlobalStoreService.TabControlGuids.Ten, userCtlGuid10, "TabItem10AddUserControl", tabItem10UserControl, tabItem10Region, tabItem10Regionkey);
       TabItemActions.RemoveUserControl<TabItem10>(GlobalStoreService.TabControlGuids.Ten, userCtlGuid10, "TabItem10RemoveUserControl", tabItem10UserControl, tabItem10Region, tabItem10Regionkey);
            
            return tabItm10;
        }
    }
}
